let glmaxtrix = require('gl-matrix');
let vec3 = glmaxtrix.vec3;
let myTools = require('./utils/mytools');

class Color3 {
    constructor(r = 1.0, g = 1.0, b = 1.0) {
        this.data = vec3.fromValues(r, g, b);
    }

    get r() {
        return this.data[0];
    }

    set r(value) {
        this.data[0] = value;
    }

    get g() {
        return this.data[1];
    }

    set g(value) {
        this.data[1] = value;
    }

    get b() {
        return this.data[2];
    }

    set b(value) {
        this.data[2] = value;
    }

    clone(){
        return new Color3(this.r,this.g,this.b);
    }

    set(r,g,b){
        if(myTools.Types.isObject(r)){
            this.data[0] = r.r;
            this.data[1] = r.g;
            this.data[2] = r.b;
        }else{
            this.data[0] = r;
            this.data[1] = g;
            this.data[2] = b;
        }
    }
}


//--------------------------
// 预定义一些 color
Color3.RED = new Color3(1,0,0);
Color3.GREEN = new Color3(0,1,0);
Color3.BLUE = new Color3(0,0,1);
Color3.YELLOW = new Color3(1,1,0);
Color3.HALF_YELLOW = new Color3(0.5,0.5,0);
Color3.WHITE = new Color3(1,1,1);
Color3.BLACK = new Color3(0,0,0);
Color3.GRAY = new Color3(0.6,0.6,0.6);
Color3.PURPLE = new Color3(1,0,1);

module.exports = Color3;